package com.qiji.video.config;

import com.qiji.video.web.interceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry){
        registry.addMapping("/**")
                .allowedMethods("POST","GET","PUT","DELETE","OPTION")
                .allowedHeaders("*")
                .allowedOrigins("*")
                .maxAge(3600);
    }

    @Value("${yuan.file.root.path}")
    public String fileRootPath;

    /**
     * 资源映射:把请求的/archive/** 映射到该文件根路径
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/archive/**").addResourceLocations("file:" + fileRootPath);
    }
//    @Override
//    public void addInterceptors(InterceptorRegistry registry){
//        registry.addInterceptor(new JwtInterceptor()).addPathPatterns("/auth/**");
//    }
}